package icu.study.netty.server;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @program: protobuf
 * @description:
 * @author: 1246263205@qq.com
 * @create: 2020-11-19 09:31
 */
public class Server {
    public static void main(String[] args) throws Exception {
        EventLoopGroup boss = new NioEventLoopGroup();
        EventLoopGroup work = new NioEventLoopGroup();
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        try {
            serverBootstrap.group(boss, work).channel(NioServerSocketChannel.class).childHandler(new ServerInitializer());
            ChannelFuture future = serverBootstrap.bind(8899).sync();
            ChannelFuture sync = future.channel().closeFuture().sync();
        } catch (Exception e) {
            e.printStackTrace();
            boss.shutdownGracefully();
            work.shutdownGracefully();
        }
    }
}